package util

import (
	"gpt-api/framework/codes"
	"gpt-api/pkg/design"
)

func GetTransData(lang string, code codes.Code) (tr string) {
	key := GetCodeKey(code)
	single := design.GetSingleInstance()
	basic := single.GetBasic()
	if lang == "en-US" {
		value, ok := basic.EnuslanguageMap.Load(key)
		if !ok {
			return key
		}

		return value.(string)
	} else if lang == "zh-CN" {
		value, ok := basic.ZhcnlanguageMap.Load(key)
		if !ok {
			return key
		}

		return value.(string)
	} else {
		return key
	}
}

func GetCodeKey(code codes.Code) string {
	codesMap := map[codes.Code]string{
		100401: "k_email_unreg",
		100414: "k_phone_unregister",
		100402: "k_invalid_pwd",
		100403: "k_code_wrong",
		100404: "k_account_register",
		100405: "The ticket has expired.",
		100406: "k_invalid_third_token",
		100407: "k_invalid_email",
		100408: "k_third_account_exist",
		100409: "k_account_bound_third",
		100416: "k_email_in_using",
		100415: "k_phone_used",
		100410: "k_invalid_phone",
		100417: "k_bind_info",
		100412: "k_refresh_info",
		100419: "邀请码无效",
		100422: "参数无效",
		100424: "用户余额不足",

		101001: "通知信息不存在",

		102001: "成员事件不存在",
		102002: "成员事件类型不存在",
		102003: "系统事件类型,限制操作",
		102004: "照片上传限制9张",
		102005: "成员事件信息存在,限制操作",
		102006: "出生日期不能大于死亡日期",
		102007: "提现账户不存在",
		102008: "申请提现金额不能小于50元",

		300001: "k_resource_already_exist",

		800001: "微信小程序code无效",
		800002: "微信支付信息不存在",

		900001: "唯一关系类型,此关系下已有成员存在",
		900002: "成员信息不存在",
		900003: "存在下级成员",
		900004: "图片信息不存在",
	}

	if _, ok := codesMap[code]; ok {
		return codesMap[code]
	}

	return ""
}
